package ru.spb.osll.myfit.wikiverifier.iterator;

import java.io.File;

public class FileSystemIterator {
	private static String CONTENT_TXT = "content.txt";
	private String m_fitnesseRootPath;
	private FileSystemIteratorListener m_listener;
	
	
	public FileSystemIterator(String fitnesseRootPath, FileSystemIteratorListener listener) {
		m_fitnesseRootPath = fitnesseRootPath;
		m_listener = listener;
	}
	
	public void iterate(){
		iterate(new File(m_fitnesseRootPath));
	}
	
	private void iterate(File file){
		if(file.isFile() && file.getName().equals(CONTENT_TXT)) {
			m_listener.listen(file.getAbsolutePath());
		} else if(file.isDirectory()) {
			for (File element : file.listFiles()) {
				iterate(element);
			}
		}
		m_listener.handleFinish();
	}
	
	
}
